//
//  UIButton+Extension.m
//  字典转模型
//
//  Created by dfwx on 2020/8/4.
//  Copyright © 2020 zhongdaodianzi. All rights reserved.
//

#import "UIButton+Extension.h"
#import <objc/runtime.h>

//#import <AppKit/AppKit.h>


@implementation UIButton (Extension)

static void *UIBUTTONKEY = &UIBUTTONKEY;


- (void)setButton_block:(void (^)(UIButton * _Nonnull))button_block {
    
    objc_setAssociatedObject(self, &UIBUTTONKEY, button_block, OBJC_ASSOCIATION_COPY);
}

- (void (^)(UIButton * _Nonnull))button_block {
    
    return objc_getAssociatedObject(self, &UIBUTTONKEY);
}

- (void)handleEven:(UIControlEvents)evens block:(void (^)(UIButton * _Nonnull))block {
    
    self.button_block = block;
    [self addTarget:self action:@selector(invoke:) forControlEvents:evens];
}

- (void)invoke:(UIButton *)sender {
    if (self.button_block) {
        self.button_block(sender);
    }
}

@end
